require('./index.css')

// 通用的JS工具封装
var _wm = require('util/wm.js')

// 遍历html模板到 nav-side.html
var templateIndex = require('./index.string')

var navSide = {
    option: {
        name: '',
        navList: [
            { name: 'user-center', desc: '个人中心', href: './user-center.html' },
            { name: 'order-list', desc: '我的订单', href: './order-list.html' },
            { name: 'user-pass-update', desc: '修改密码', href: './user-pass-update.html' },
            { name: 'about', desc: '关于WMall', href: './about.html' }
        ]
    },

    // 初始化
    init: function(option){
        // 合并选项
        $.extend(this.option, option)

        this.renderNav()
    },

    // 渲染导航菜单
    renderNav: function(){
        // 计算active的数据
        for(var i = 0, len = this.option.navList.length; i < len; i++){
            if(this.option.navList[i].name === this.option.name){
                this.option.navList[i].isActive = true
            }
        }
        // 渲染list数据
        var navHtml = _wm.renderHtml(templateIndex, {
            navList: this.option.navList
        })
        // 把渲染输出的html放入容器中
        $('.nav_side').html(navHtml)
    }
    
}

module.exports = navSide